package com.wmx.newspushmonitor;

import android.app.Activity;
import android.content.Intent;
import android.provider.Settings;
import android.view.View;

import com.rhino.ui.utils.SharedPreferencesUtils;
import com.rhino.ui.utils.ui.ToastUtils;
import com.wmx.newspushmonitor.base.BaseSimpleTitleHttpActivity;
import com.wmx.newspushmonitor.databinding.ActivityMainBinding;
import com.wmx.newspushmonitor.databinding.ActivityNotifySettingBinding;
import com.wmx.newspushmonitor.util.UiUtils;

/**
 * @author LuoLin
 * @since Create on 2019/3/6.
 */
public class NotifySettingActivity extends BaseSimpleTitleHttpActivity<ActivityNotifySettingBinding> {

    private boolean openServer1 = true;
    private boolean openServer2 = true;

    public static void show(Activity activity, boolean isFirst) {
        Intent intent = new Intent(activity, NotifySettingActivity.class);
        intent.putExtra("isFirst", isFirst);
        activity.startActivity(intent);
    }

    @Override
    public void setContent() {
        setContentView(R.layout.activity_notify_setting);
    }

    @Override
    public void initView() {
        setBaseOnClickListener(dataBinding.btOpenServer1, dataBinding.btOpenServer2);
        mActionBarHelper.setTitle("权限设置");
        if (getIntent().getBooleanExtra("isFirst", false)) {
            openServer1 = false;
            openServer2 = false;
            mActionBarHelper.setTitleBackKeyVisible(false);
            mActionBarHelper.addTitleRightKey("立即开始", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MainActivity.show(NotifySettingActivity.this);
                    SharedPreferencesUtils.getInstance().putBoolean("isFirst", false);
                    finish();
                }
            });
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (!openServer1) {
            openServer1 = true;
            dataBinding.btOpenServer1.performClick();
            ToastUtils.show("第一步：设置【" + getString(R.string.app_name) + "】通知监听权限");
        } else if (!openServer2) {
            openServer2 = true;
            dataBinding.btOpenServer2.performClick();
            ToastUtils.show("第二步：设置【" + getString(R.string.app_name) + "】通知使用权限");
        }
    }

    @Override
    public void baseOnClickListener(View v) {
        super.baseOnClickListener(v);
        if (v == dataBinding.btOpenServer1) {
            Intent accessibleIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
            startActivity(accessibleIntent);
        } else if (v == dataBinding.btOpenServer2) {
            startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
        }
    }

}
